home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jazlib.arc / JZMENU.C < prev    next >
Text File  |  1988-12-18  |  1KB  |  71 lines

  1. #include <jaz.h>
  2. #include <keys.h>
  3. #include <jzscreen.h>
  4. extern TWINDOW g_window;
  5.  
  6. jzmenu(flist , ffore , fback , fnum , fkeys)
  7. char **flist;
  8. int ffore,fback,fnum;
  9. char *fkeys;
  10. {
  11.   TWINDOW *wptr;
  12.   int w,wcol,wdefault;
  13.   int wchr,wscan,wlen,wwidth;
  14.   int wstarty,wstartx;
  15.   int row,col,start,end;
  16.  
  17.   if ( ! fnum ) return(-1);    /* nothing to list */
  18.  
  19.   jzgetcur(&row,&col,&start,&end);
  20.  
  21.   jzsetcur(0x20,0x20);
  22.  
  23.   wwidth = fnum + 2;
  24.   wlen = 0;
  25.   for (w = 0 ; w < fnum ; w ++) wlen = max(wlen,strlen(flist[w]));
  26.  
  27.   wlen += 4;    /* space on both sides and allow for box */
  28.  
  29.   wstartx = (80 - wlen) >> 1;
  30.   wstarty = (24 - wwidth) >> 1;
  31.  
  32.   wptr = jzopnwnd(0xff,wstarty,wstartx,wlen,wwidth,ffore,fback);
  33.  
  34.   for (w = 0 ; w < fnum ; w ++)
  35.     jzscrprn(flist[w],wstarty+w+1,wstartx+2,
  36.          (fback*16|ffore) & 0x7f);
  37.  
  38.   wdefault = 0;
  39.   do {
  40.     jzscrprn(flist[wdefault],wstarty+wdefault+1,wstartx+2,
  41.         (ffore*16|fback) & 0x7f);
  42.  
  43.     wchr = jzinkey(&wscan);
  44.  
  45.     jzscrprn(flist[wdefault],wstarty+wdefault+1,wstartx+2,
  46.          (fback*16|ffore) & 0x7f);
  47.  
  48.     if (strchr(fkeys,wscan)) {
  49.       wdefault = -1;
  50.       wscan = ENTER;
  51.     }
  52.  
  53.     switch(wscan) {
  54.       case UARR :
  55.     wdefault = --wdefault < 0 ? fnum - 1 : wdefault;
  56.     break;
  57.       case DARR :
  58.     wdefault = ++wdefault == fnum ? 0 : wdefault;
  59.     break;
  60.     }
  61.   } while(wscan != ENTER);
  62.  
  63.   jzrstwnd(wptr);
  64.   jzdelete(0xff);
  65.  
  66.   jzsetcur(start,end);
  67.  
  68.   return(wdefault);
  69.  
  70. }
  71.